package io.mya.currencypay.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;

import io.mya.app.utils.HttpUtils;
import io.mya.common.utils.R;
import io.mya.currencypay.util.HttpClientUtil;

/**
 * 币转币汇率
 * 
 * @author helin
 * @RequestParam Map<String, Object> params
 */
@RestController
@RequestMapping("/sys/exchangeRate")
public class ExchangeRateController {
	//Api查询币与币之间的市场信息URL
	public static String rateurl = "https://shapeshift.io/marketinfo/";
	
	//Api查询币与币之间的市场信息URL
	public static String thenearfutureurl = "https://shapeshift.io/recenttx/";
	
	//Api查询获取支持硬币列表URL
	public static String coinlisturl = "https://shapeshift.io/getcoins";
	
	
	/**
	 * 查询近期交易清单 
	 * 
	 */
	@RequestMapping("/thenearfuture")
	public R thenearfuture() {
		HttpClientUtil client = new HttpClientUtil();
		String doGet = client.doGet(thenearfutureurl+20); 
		JSONArray myJsonArray = JSONArray.parseArray(doGet);
		return R.ok().put("doGet", myJsonArray);

	}
	
	/**
	 * 获取支持硬币列表
	 * 
	 */
	@RequestMapping("/coinlis")
	public R coinlis() {
		HttpClientUtil client = new HttpClientUtil();
		String doGet = client.doGet(coinlisturl); 
		com.alibaba.fastjson.JSONObject myJsonArray = com.alibaba.fastjson.JSONObject.parseObject(doGet);
		//JSONArray myJsonArray = JSONArray.parseArray(doGet);
		return R.ok().put("doGet", myJsonArray);


	}
	/**
	 * 查询币与币之间的市场信息接口
	 * 
	 * @RequestParam turnout,receive
	 * 
	 * 	  turnout:转出币种                       receive:接受币种    
	 * 
	 */
	@RequestMapping("/rate")
	public R rate(String turnout,String receive) {
		HttpClientUtil client = new HttpClientUtil();
		String doGet = client.doGet(rateurl+turnout+"_"+receive); 
		com.alibaba.fastjson.JSONObject myJsonArray = com.alibaba.fastjson.JSONObject.parseObject(doGet);
		return R.ok().put("doGet", myJsonArray);


	}
	
	
}
